home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / 2600KeyNabber.txt < prev    next >
Text File  |  1997-11-26  |  2KB  |  70 lines

  1. This was taken from the Autumn issue of 2600...
  2.  
  3. /* This is a key capturing program using a jGNE filter, for the Macintosh */
  4. /* This is written to be compiled with THINK C or C++ and should be built */
  5. /* as a system extension                                                  */
  6.  
  7. #include <Resources.h>
  8. #include <Memory.h>
  9. #include <Events.h>
  10. #include <SetUpA4.h>
  11. #include <SysEqu.h>
  12. static void *gOldJGNE;
  13.  
  14. static pascal * SetJGNEFilter (void *newFilter)
  15. {
  16.         void *result = *(voide **) JGNEFilter;
  17.         *(long *) JGNEFilter = (long) newFilter;
  18.         return (result);
  19. }
  20.  
  21. static Boolean myGNE (EventRecord *event, Booleab preResult)
  22. {
  23.         Boolean postResult = preResult;
  24.  
  25.         if (event->what == mouseDown)
  26.                 SysBeep (10);
  27.  
  28.         return (postresult);
  29. }
  30.  
  31. static void myJGNE (void)
  32. {
  33.         static Boolean inJGNE;
  34.  
  35.         asm
  36.         {
  37.                 MOVE.L  A1,A0           ; save event record pointer from GetA4
  38.                 JSR     GetA4           ; point A1 at our A4
  39.                 MOVE.L  A4,-(A7)        ; save old A4
  40.                 MOVE.L  (A1),A4         ; get new A4
  41.                 MOVE.L  A0,AT           ; restore old A1
  42.                 TST.B   inJGNE          ; is myJGNE busy?
  43.                 BNE     @1              ; yes, so bail
  44.                 MOVE.B  #true,inJGNE    ; mark myJGNE busy
  45.                 MOVE.W  D0,-(A7)        ; push pre-result
  46.                 MOVE.L  A1,-(A7)        ; push even record pointer
  47.                 JSR     myJGNE          ; do the real work
  48.                 MOVE.L  (A7)+,A1        ; restore event record pointer
  49.                 ADDQ.L  #2,A7           ; pop pre-result; post result in D0
  50.                 ASL.W   #8,D0           ; bump C boolean to Lisa
  51.                 MOVE.W  D0,8(A7)        ; stash result where caller expects it
  52.                 MOVE.B  #false,inJGNE   ; mark myJGNE not busy @1
  53.                 MOVE.L  (A7)+,A4        ; restore A4
  54.                 MOVE.L  A0,-(A7)        ; return to previous JGNE
  55.         }
  56. }
  57.  
  58. pascal void main (void)
  59. {
  60.         void *me;       asm {   MOVE.L  A0,me   }
  61.  
  62.         RememberA0 ( );
  63.         SetUpA4 ( );
  64.  
  65.         DetachResource (RecoverHandle (me));
  66.         gOldJGNE = SetJGNEFilter (myJGNE);
  67.  
  68.         RestoreA4 ( );
  69. }
  70.